package com.sk.weichat.adapter;

import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.weichat.R;
import com.sk.weichat.bean.Friend;
import com.sk.weichat.bean.RoomMember;
import com.sk.weichat.db.InternationalizationHelper;
import com.sk.weichat.db.dao.RoomMemberDao;
import com.sk.weichat.helper.AvatarHelper;
import com.sk.weichat.ui.base.CoreManager;
import com.sk.weichat.util.AppUtils;
import com.sk.weichat.view.HeadView;

import java.util.List;

public class SearchGroupRecodeAdapter extends BaseQuickAdapter<Friend, BaseViewHolder> {
    public String keyword;

    public SearchGroupRecodeAdapter(List<Friend> data) {
        super(R.layout.item_search_group_recode, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Friend item) {
        helper.addOnClickListener(R.id.layout_search_friend_item);
        HeadView avatar_imgS = helper.getView(R.id.avatar_imgS);
        TextView tv_search_remarkName = helper.getView(R.id.tv_search_remarkName);
        TextView roleS = helper.getView(R.id.roles);
        AvatarHelper.getInstance().displayAvatar(CoreManager.requireSelf(mContext).getUserId(), item, avatar_imgS);

        SpannableStringBuilder style = null;
        if (TextUtils.isEmpty(item.getRemarkName())){
            style = AppUtils.TextColorkeywordByBule(mContext,item.getNickName(),getKeyword());
        }else {
            AppUtils.TextColorkeywordByBule(mContext,item.getRemarkName(),getKeyword());
        }
//        SpannableStringBuilder style = AppUtils.TextColorkeywordByBule(mContext,item.getNickName(),getKeyword());
        tv_search_remarkName.setText(style!=null?style:item.getNickName());
        RoomMember member = RoomMemberDao.getInstance().getSingleRoomMember(item.getRoomId(),CoreManager.getSelf(mContext).getUserId());
        if (member != null) {
            if (member.getRole() == 1) {
                roleS.setVisibility(View.VISIBLE);
                roleS.setBackgroundResource(R.drawable.bg_role1);
                roleS.setText(InternationalizationHelper.getString("JXGroup_Owner"));
            } else if (member.getRole() == 2) {
                roleS.setVisibility(View.VISIBLE);
                roleS.setBackgroundResource(R.drawable.bg_role2);
                roleS.setText(InternationalizationHelper.getString("JXGroup_Admin"));
            } else {
                roleS.setVisibility(View.GONE);
//                roleS.setBackgroundResource(R.drawable.bg_role3);
//                roleS.setText(InternationalizationHelper.getString("JXGroup_RoleNormal"));
            }
        }

    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }
}
